package cn.zcx;

import java.awt.datatransfer.FlavorTable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * description:
 * author:zcx
 * lenovo
 * 时间：2022.02.07.17.08
 */
public class T13 {
    CountDownLatch latch=new CountDownLatch(5);
    void worker(){
        String t=Thread.currentThread().getName();
        System.out.printf("线程：%s,启动..%n",t);
        for (int i = 0; i < 5; i++) {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.printf("%s:%d%n",t,i);
        }
       latch.countDown();
    }
    void over(){
        try {
            latch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    String t=Thread.currentThread().getName();
        System.out.printf("收尾线程：%s,启动..%n",t);

        System.out.println("所有线程结束");
    }
    public static void main(String[] args) {
        var t=new T13();
        new Thread(t::worker,"T1").start();
        new Thread(t::worker,"T2").start();
        new Thread(t::worker,"T3").start();
        new Thread(t::worker,"T4").start();
        new Thread(t::worker,"T5").start();
        //最后执行
        new Thread(t::over,"OVER").start();
        //main线程
        t.worker();
    }
}
